package com.cn.thread;

import java.util.concurrent.*;

/**
 * @author hels
 * @version 1.0
 * @date 2022/3/8 11:32
 */
public class ThreadPoolDemo4 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

//        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(4, 10,
//                3000, TimeUnit.MILLISECONDS, WorkQueue, threadFactory, rejectHandler);
        ExecutorService excutors = Executors.newCachedThreadPool();
        excutors.execute(new MyRunnable4());
        Future<String> future = excutors.submit(new MyCallable4());
        String str = future.get();
        System.out.println(str);
        excutors.shutdown();

        FutureTask<String> task = new FutureTask<>(new MyCallable4());
        Thread thread = new Thread(task);
        thread.setName("【现成】");
        thread.start();
        System.out.println(task.get());


    }

}

class MyRunnable4 implements Runnable{
    @Override
    public void run() {
        System.out.println("我要一个教练run  " + Thread.currentThread().getName());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("他run来了，教完课又回去了");
    }
}
class MyCallable4 implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "来了一个教练call");
        Thread.sleep(3500);
        System.out.println(Thread.currentThread().getName() + "教练call走了");
        return "[MyCallable4]";
    }
}



